﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wq.Application;
using Wq.Framework.Base.Admin;

namespace Wq.Manager.API
{
    /// <summary>
    /// 地区管理
    /// </summary>
    [Route("admin/file/region")]
    public class RegionController : ManagerBaseController
    {
        
        private readonly RegionApplication application;

        /// <summary>
        /// 地区管理
        /// </summary>
        public RegionController(RegionApplication application)
        {
            this.application = application;
        }

        /// <summary>
        /// 地区列表 
        /// </summary>
        /// <param name="id">上级Id 0表示一级</param>
        /// <param name="level">深度</param>
        /// <returns></returns>
        [HttpGet("list")]
        public IActionResult List(long id = 0, int level = 4) => SuccessResult(application.List(id, level));

        /// <summary>
        /// 获取下级集合
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        [HttpGet("subs/{parentId}")]
        public IActionResult Subs(int parentId) => SuccessResult(application.Subs(parentId));

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="name">地区名称</param>
        /// <param name="parentId">上级Id</param>
        /// <returns></returns>
        [HttpGet("create")]
        public IActionResult Create(string name, int parentId)
        {
            application.Create(name, parentId);
            return SuccessResult();

        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id">Id</param>
        /// <param name="name">地区名称</param>
        /// <returns></returns>
        [HttpGet("save")]
        public IActionResult Save(int id, string name)
        {
            application.Save(id, name);
            return SuccessResult();
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">Id</param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public IActionResult Remove(long id)
        {
            application.Remove(id);
            return SuccessResult();
        }

        /// <summary>
        /// 地址文件
        /// </summary>
        /// <returns></returns>
        [HttpGet("file")]
        public IActionResult GetFile() => SuccessResult(application.GetFile);



        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public IActionResult Details(long id) => SuccessResult(application.Details(id));
    }
}
